<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">栏目管理</h1>
</div>

<div class="wrapper-md"  >
  <div class="panel panel-default">
    <div ng-controller="infoEditCtrl">
      <div class="row">

        <div class="col-sm-12" >
          <form name="form-contact" ng-submit="processForm()" class="form-horizontal">

            <div class="panel-heading">
              <span class="h4">
                <button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>
              </span>
            </div>
            <div class="panel-body">



             <div class="panel-heading">
              <span class="h4" style="color: blue;">栏目简介信息</span>
            </div>
            <div class="form-group">
              <label class="col-sm-1 control-label">父菜单</label>
              <div class="col-sm-5">
        <input type="text" class="form-control" placeholder="父级" ng-model="fathers[0].ClassName" readonly>
               <input type="hidden" class="form-control" placeholder="编号" ng-model="fathers[0].Id">

             </div>


             <label class="col-sm-1 control-label">栏目名称</label>
             <div class="col-sm-5">
               <input type="text" class="form-control" placeholder="菜单名称" ng-model="contact.ClassName" required >
             </div>
           </div>

           <div class="line line-dashed b-b line-lg pull-in"></div>


           <div class="form-group">
             <label  class="col-sm-1 control-label">排序</label>
             <div class="col-sm-5">
              <input type="text" class="form-control"  ng-model="contact.ClassDisplayOrder" required >
            </div>

          </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>


          <div class="form-group">
           <label class="col-sm-1 control-label">备注</label>  
           <div class="col-sm-10">
             <textarea class="form-control" ng-model="contact.ClassRemark" rows="6" placeholder="备注">{{contact.ClassRemark}}</textarea>
           </div>
         </div>
         <div class="line line-dashed b-b line-lg pull-in"></div>


         <div class="form-group">
           <label class="col-sm-1 control-label">图标</label>  
           <div class="col-sm-5">
            <input type="text" class="form-control" placeholder="" ng-model="contact.ClassSmallIcon" >
          </div>
        </div>
      </div>
      <div class="panel-body">

       <div class="panel-heading">
         <span class="h4" style="color: blue;">配置信息</span>
       </div>
       <div class="form-group">
        <label class="col-sm-1 control-label">启用/停用</label>
        <div class="col-sm-1">
         <label class="i-switch m-t-xs m-r">
          <input type="checkbox" ng-model="ClassReadOnly" >
          <i></i>
        </label>
      </div>


      <label class="col-sm-1 control-label">PC</label>
      <div class="col-sm-1">
       <label class="i-switch m-t-xs m-r">
        <input type="checkbox" ng-model="ClassDisplayOnPc" >
        <i></i>
      </label>
    </div>
    <label class="col-sm-1 control-label">Phone</label>
    <div class="col-sm-1">
     <label class="i-switch m-t-xs m-r">
      <input type="checkbox" ng-model="ClassDisplayOnPhone" >
      <i></i>
    </label>
  </div>


  <label class="col-sm-1 control-label">Pad</label>
  <div class="col-sm-1">
   <label class="i-switch m-t-xs m-r">
    <input type="checkbox"  ng-model="ClassDisplayOnPad"  >
    <i></i>
  </label>
</div>

<label class="col-sm-1 control-label">TV</label>
<div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
  <input type="checkbox"  ng-model="ClassDisplayOnTv"  >
  <i></i>
</label>
</div>


</div>


<div class="line line-dashed b-b line-lg pull-in"></div>


<!--隐藏字段-->
<input type="hidden"  ng-model="contact.Id"  >
<input type="hidden"  ng-model="contact.ClassUuid"  >
<input type="hidden"  ng-model="contact.AdderId"  >
<input type="hidden"  ng-model="contact.AdderName"  >
<input type="hidden"  ng-model="contact.AddTime"  >
<input type="hidden"  ng-model="contact.UpdaterId"  >
<input type="hidden"  ng-model="contact.UpdaterName"  >
<input type="hidden"  ng-model="contact.UpdateTime"  >
<input type="hidden"  ng-model="contact.DelFlag" ng-init="contact.DelFlag='0' ">
<!--隐藏字段-->

</div>


<footer class="panel-footer text-right bg-light lter">
  <button type="submit" class="btn btn-success">提交</button>
</footer>
</div>
</form>
</div>
</div>

</div>
</div>




</div>


<!--angularjs-->
<script type="text/javascript">
'use strict';
app.controller('infoEditCtrl', function ($scope, $state, $stateParams,$http,$window) {

//返回按钮：开始
$scope.$window = $window;
$scope.goBack = function() {
  $state.go('app.movie.managerColumn');
};
//返回按钮：结束
var infoId = $stateParams.infoId;


 //如果infoId不为空，查询详情：开始
 if(''!=infoId&&infoId!=undefined){
  var getInfoUrl = API_URL+"program_class?query=delflag:0,Id:"+infoId;    

  $http.get(getInfoUrl).success(function (response) {
   var obj = response[0];
   var fatherId = obj.FatherId;
   if(fatherId!=''&&fatherId!=undefined){
     var getInfoUrl = API_URL+"program_class?query=delflag:0,Id:"+fatherId;    

     fatherDatas =  MY_ASYNC_AJAX(getInfoUrl);

     $scope.fathers = fatherDatas;
   }
   obj.ClassDisplayOrder = Number(obj.ClassDisplayOrder);
   if("0" == obj.ClassReadOnly){
    $scope.ClassReadOnly = true;
  }else {
     $scope.ClassReadOnly = false;
  }
  if("1" == obj.ClassDisplayOnPad){
    $scope.ClassDisplayOnPad = true;
  }else {
     $scope.ClassReadOnly = false;
  }
  if("1" == obj.ClassDisplayOnPc){
    $scope.ClassDisplayOnPc = true;
  }else {
     $scope.ClassDisplayOnPc = false;
  }
  if("1" == obj.ClassDisplayOnPhone){
    $scope.ClassDisplayOnPhone = true;
  }else {
     $scope.ClassDisplayOnPhone = false;
  }
  if("1" == obj.ClassDisplayOnTv){
    $scope.ClassDisplayOnTv = true;
  }else {
     $scope.ClassDisplayOnTv = false;
  }
  $scope.contact = obj;

  console.log(JSON.stringify($scope.contact));
});
}else {
    //说明是 增加
    var classId = $stateParams.classId;
    var fatherDatas;
    if(classId==''||classId==undefined||classId==null){
     fatherDatas = [{Id : "0", ClassName : "顶级菜单"}];
   }else {
     var getInfoUrl = API_URL+"program_class?query=delflag:0,Id:"+classId;    

     fatherDatas =  MY_ASYNC_AJAX(getInfoUrl);

   }

   $scope.fathers = fatherDatas;


 }


  //表单提交开始
  $scope.processForm= function (){
    debugger;

  //1.参数处理

//发起POST请求
var postInfoUrl = API_URL+"program_class";
var formData =  $scope.contact;

  //1.参数处理
  formData.AddTime = getNowDBFormatDate();
  formData.UpdateTime = getNowDBFormatDate();
  formData.AdderId = 1;
  formData.AdderName = '1';
  formData.UpdaterId = 1;
  formData.UpdaterName = '1';
  formData.ClassUuid='';
  formData.ClassDisplayOrder=formData.ClassDisplayOrder + '';
 
  //formData.FatherId = Number($scope.fathers[0].Id);

  if($scope.ClassReadOnly==true){
    formData.ClassReadOnly="0";
  }else {
    formData.ClassReadOnly="1";
  }
  if($scope.ClassDisplayOnPad==true){
    formData.ClassDisplayOnPad="1";
  }else {
    formData.ClassDisplayOnPad="0";
  }
   if($scope.ClassDisplayOnPc==true){
    formData.ClassDisplayOnPc="1";
  }else {
      formData.ClassDisplayOnPc="0";
  }
   if($scope.ClassDisplayOnPhone==true){
    formData.ClassDisplayOnPhone="1";
  }else {
    formData.ClassDisplayOnPhone="0";
  }
   if($scope.ClassDisplayOnTv==true){
    formData.ClassDisplayOnTv="1";
  }else {
     formData.ClassDisplayOnTv="0";
  }

  console.log(JSON.stringify(formData));
  if("undefined"!=typeof(formData.Id)){

    $.ajax({  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl+'/'+infoId, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                    console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 
                    top.layer.msg('保存成功', {icon: 6});
                  //2.成功跳转页面
                  $state.go('app.movie.managerColumn');
                }  
              }); 
  }else{

   $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'post', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                    console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $state.go('app.movie.managerColumn');
               }  
             }); 

 }
}

});
</script>
<!--angularjs-->










